package com.ce.webframework.sec.service.impl;

import java.util.List;

import com.ce.webframework.sec.model.SecToolbarDO;
import com.ce.webframework.sec.model.SecToolbarTempDO;
import com.ce.webframework.sec.service.ISecToolbarService;
import com.ce.webframework.sec.dao.ISecToolbarDao;
import com.ce.webframework.sec.dao.ISecToolbarTempDao;

public class SecToolbarServiceImpl implements ISecToolbarService{

	@SuppressWarnings("unused")
	private ISecToolbarDao secToolbarDao;
	@SuppressWarnings("unused")
	private ISecToolbarTempDao secToolbarTempDao;



	public void setSecToolbarDao(ISecToolbarDao secToolbarDao) {
		this.secToolbarDao = secToolbarDao;
	}



	public void setSecToolbarTempDao(ISecToolbarTempDao secToolbarTempDao) {
		this.secToolbarTempDao = secToolbarTempDao;
	}


	public List<SecToolbarTempDO> getUnuseCutMenus(Long userId,List functionIds) {

		return secToolbarTempDao.getUnuseCutMenus(userId,functionIds);
	}

	public List<SecToolbarDO> getUseCutMenus(Long userId, Long epId,List <String>functionIds) {
		// TODO Auto-generated method stub
		return  secToolbarDao.getUseCutMenus(userId,epId,functionIds);
	}




	/**
	 *
	 * 功能描述: 当移快捷菜单时更新当前菜单的位置并保存
	 *
	 *@param applyId 应用标志(页面容器标志：rss_body+applyId)
	 *@param orderNum 排序字段
	 *@param cutId  字段主键
	 *
	 */

	public void updateCutMenuWhenMove(String applyId, String orderNum, Long cutId,Long userId,Long epId){
		System.out.println("applyId===============>"+applyId);
		System.out.println("orderNum===============>"+orderNum);
		System.out.println("cutId===============>"+cutId);


		SecToolbarTempDO temp = (SecToolbarTempDO)secToolbarTempDao.findById(cutId);//得到要查找的拖拉源对象
		if (temp != null){
			//容器0代表是未应用状态
			System.out.println("temp.getSecToolbar()==============="+temp.getSecToolbar());

			if (temp.getSecToolbar()!=null&&temp.getSecToolbar().getUserId().equals(userId)){
				if("0".equals(applyId)){
					secToolbarDao.doDelete(temp.getSecToolbar());
					//更新应用容器拖拉源序号
					secToolbarDao.updateCutMenu(temp.getSecToolbar(),epId,userId);
				}else{
					//更新应用容器的拖拉源序号
					secToolbarDao.updateCutMenu(temp.getSecToolbar(),orderNum,epId,userId);

				}


			} else {

				if("1".equals(applyId)){

					if(secToolbarDao.findToolbarByTempId(temp.getToolbarTempId(),userId)==0){

						secToolbarDao.updateCutMenu(orderNum,epId,userId);
						SecToolbarDO toolBar= new SecToolbarDO();
						toolBar.setEpId(epId);
						toolBar.setOrderNum(new Integer(orderNum));
						toolBar.setSecToolbarTemp(temp);
						toolBar.setUserId(userId);
						secToolbarDao.doSave(toolBar);

					}



				}

			}


		}
		temp = null;


	}

}
